//
//  BGOwnAppraiseListCell.m
//  bigMall
//
//  Created by LTOVE on 16/9/18.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGOwnAppraiseListCell.h"
#import "BGOwmAppraiseList.h"
//#import "BGOwmAppraiseList.h"
static NSString *const reuseIdentify = @"cell";

@implementation BGOwnAppraiseListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    // Configure the view for the selected state
}

- (void)setModel:(BGOwmAppraiseListRes *)model
{
    _model = model;
    [self setUpAllSubviewsWithModel:model];
}


- (void)setUpAllSubviewsWithModel:(BGOwmAppraiseListRes *)model
{
    //清空cell
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    //创建内容视图
    UIView *contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenW, 120)];
//    contentView.backgroundColor = read_;
    //标题
    UILabel *title = [UILabel new];
    title.text = model.title;
    title.font = Font34;
    title.textColor = textBlackColor;
    [title sizeToFit];
    title.point = CGPointMake(BGMaginLeft, 10);
    [contentView addSubview:title];
    //分割线
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(BGMaginLeft, CGRectGetMaxY(title.frame) + 10, screenW - 2 * BGMaginLeft, 1)];
    lineView.backgroundColor = dockwhite_;
    [contentView addSubview:lineView];
    //分数
    UILabel *label2 = [self labelWithScore:model.score_2 andTitle:@"发货品质"];
    
    UILabel *label1 = [self labelWithScore:model.score_1 andTitle:@"服务态度:"];
    UILabel *label3 = [self labelWithScore:model.score_3 andTitle:@"发货效率"];
    CGFloat magin = (screenW - 2 * BGMaginLeft - label2.width - label1.width - label3.width) /4.0;
    label1.y = label2.y = label3.y = CGRectGetMaxY(lineView.frame) + 5;
    label2.centerX = screenW * 0.5;
    label1.x = BGMaginLeft;
    label2.x = CGRectGetMaxX(label1.frame) + 10;
    label3.x = CGRectGetMaxX(label2.frame) + 10;
    UIView *line1 = [self addLineViewWithFrame:CGRectMake(CGRectGetMaxX(label1.frame) + 5, label1.y, 1, label1.height)];
    UIView *line2 = [self addLineViewWithFrame:CGRectMake(CGRectGetMaxX(label2.frame) + 5, label2.y, 1, label2.height)];
    [contentView addSubview:label1];
    [contentView addSubview:line1];
    [contentView addSubview:label2];
    [contentView addSubview:line2];
    [contentView addSubview:label3];
    //评价内容
    UILabel *contentLabel = [UILabel new];
    contentLabel.text = model.content;
    contentLabel.font = Font30;
    contentLabel.textColor = textBlackColor;
    [contentLabel sizeToFit];
    contentLabel.width = screenW - 2 * BGMaginLeft;
    contentLabel.x = BGMaginLeft;
    contentLabel.y = CGRectGetMaxY(label1.frame) + 5;
    [contentView addSubview:contentLabel];
    //日期
    UILabel *dateLabel = [UILabel new];
    dateLabel.text = model.add_time;
    dateLabel.font = Font30;
    dateLabel.textColor = textGrayColor;
    [dateLabel sizeToFit];
    dateLabel.x = contentLabel.x;
    dateLabel.y = CGRectGetMaxY(contentLabel.frame) + 5 ;
    [contentView addSubview:dateLabel];
    UIView *lineViews = [[UIView alloc]initWithFrame:CGRectMake(0, contentView.height - 10, screenW , 10)];
    lineViews.backgroundColor = dockwhite_;
    [contentView addSubview:lineViews];
    [self.contentView addSubview:contentView];
}

- (UIView *)addLineViewWithFrame:(CGRect)frame
{
    UIView *view = [[UIView alloc]initWithFrame:frame];
    view.backgroundColor = textBlackColor;
    return view;
}

- (UILabel *)labelWithScore:(NSString *)score andTitle:(NSString *)title
{
    UILabel *label = [UILabel new];
    label.text = [NSString stringWithFormat:@"%@:%@分",title,score];
    label.font = Font30;
    label.textColor = textBlackColor;
    [label sizeToFit];
    return label;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    BGOwnAppraiseListCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentify];
    if (!cell) {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentify];
    }
    return cell;
}

@end
